//
//  asinocAppDelegate.m
//  asinoc
//
//  Created by Colin Leung on 20/05/2010.
//  Copyright Digi3 Studio 2010. All rights reserved.
//

#import "asinocAppDelegate.h"
#import "asinocViewController.h"
#import "ASMacro.h"
#import "Stage.h"
#import "BitmapData.h"
#import "Bitmap.h"

@interface asinocAppDelegate()
	-(UIButton*) makeButton:(NSString*)img :(NSString*)down_img;
@end

@implementation asinocAppDelegate

@synthesize window;
@synthesize viewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
	Stage *stage = [[[Stage alloc] initWithView:window] autorelease];
	
	BitmapData *bd = [[[BitmapData alloc] initWithFilename:@"button.png"] autorelease];
	Bitmap *bmp = [[[Bitmap alloc] init] autorelease];
	bmp.bitmapData = bd;
	[stage addChild:bmp];

	bmp.x = 100;
	bmp.y = 100;

	UIButton *btn = [self makeButton:@"button.png" :@"button_press.png"];
	[btn addTarget:self action:@selector(test:forEvent:) forControlEvents:UIControlEventAllTouchEvents];
	[window addSubview: btn];
	[window makeKeyAndVisible];
}

-(void) test:(id)sender forEvent:(UIEvent *)event{
	NSLog(@"%@", sender);
	NSLog(@"----------");
	NSLog(@"%@", event);
}
	
-(UIButton*) makeButton:(NSString*)img :(NSString*)down_img{
	UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
	UIImage *up = [UIImage imageNamed:img];
	UIImage *down = [UIImage imageNamed:down_img];
	[b setBackgroundImage:up	forState:UIControlStateNormal];
	[b setBackgroundImage:down	forState:UIControlStateHighlighted];
	b.layer.frame = CGRectMake(0,0,up.size.width,up.size.height);
	return b;
}

- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end
